<?php

require __DIR__ . '/../../vendor/autoload.php';
require __DIR__ . '/../Mqtt.php';

$mqtt = new Mqtt;
$mqtt->createChannel();
$mqtt->createExchange('topic-exchange', 'topic');


$routerKeys = ['mysql.log', 'nginx.log', 'php.log', 'ack.ok'];

$i = 1;
while(true) {
    $msg = "hello,mqtt_{$i}\n";

    $index = $i%4;
    $mqtt->publishMsg($msg, [], $routerKeys[$index]);
    echo $msg;
    $i++;

    sleep(mt_rand(1,10)*0.1);
}

$mqtt->close();
